package com.xuxu.blog.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * @className: DateConfig
 * @author: Maxuxu
 * @date: 2022/8/24 19:34
 * @description: mybatis的数据库添加和更新数据的时间操作
 */
@Component
public class DateConfig implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {
        //设置属性值
        this.setFieldValByName("time",new Date(),metaObject);
        this.setFieldValByName("utime",new Date(),metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {
        this.setFieldValByName("utime",new Date(),metaObject);
    }
}
